<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>消息队列：分布式系统的核心通信机制</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 1px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
            border-color: #667eea;
        }
        
        .section-title {
            position: relative;
            padding-left: 20px;
        }
        
        .section-title::before {
            content: '';
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 4px;
            height: 24px;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 2px;
        }
        
        .feature-icon {
            width: 60px;
            height: 60px;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            border-radius: 16px;
            color: white;
            font-size: 24px;
            margin-bottom: 16px;
        }
        
        .mq-card {
            background: white;
            border-radius: 16px;
            padding: 24px;
            position: relative;
            overflow: hidden;
        }
        
        .mq-card::before {
            content: '';
            position: absolute;
            top: 0;
            left: 0;
            right: 0;
            height: 4px;
            background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
        }
        
        .tech-badge {
            display: inline-block;
            padding: 4px 12px;
            background: #f3f4f6;
            border-radius: 20px;
            font-size: 14px;
            margin: 4px;
            transition: all 0.2s ease;
        }
        
        .tech-badge:hover {
            background: #e5e7eb;
            transform: scale(1.05);
        }
        
        .drop-cap {
            float: left;
            font-size: 4em;
            line-height: 0.8;
            margin: 0.1em 0.1em 0 0;
            font-weight: 700;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            font-family: 'Noto Serif SC', serif;
        }
        
        .mermaid {
            background: white;
            border-radius: 12px;
            padding: 20px;
            box-shadow: 0 4px 20px rgba(0,0,0,0.05);
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .animate-fade-in {
            animation: fadeInUp 0.6s ease-out;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6">
            <div class="max-w-4xl mx-auto text-center animate-fade-in">
                <h1 class="text-5xl md:text-6xl font-bold mb-6">消息队列</h1>
                <p class="text-xl md:text-2xl mb-8 opacity-90">分布式系统的核心通信机制</p>
                <div class="flex justify-center space-x-8 text-lg">
                    <div class="flex items-center">
                        <i class="fas fa-network-wired mr-2"></i>
                        <span>系统解耦</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-bolt mr-2"></i>
                        <span>高性能</span>
                    </div>
                    <div class="flex items-center">
                        <i class="fas fa-shield-alt mr-2"></i>
                        <span>高可靠</span>
                    </div>
                </div>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        
        <!-- Introduction -->
        <section class="mb-16 animate-fade-in">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-6 section-title">引言</h2>
                <p class="text-lg leading-relaxed text-gray-700">
                    <span class="drop-cap">在</span>分布式系统架构中，服务之间的通信是一个核心问题。消息队列（Message Queue，MQ）作为一种异步通信机制，能够解耦系统组件、提高系统可扩展性，并优化性能。它已成为现代微服务架构中不可或缺的基础设施组件。
                </p>
            </div>
        </section>

        <!-- Basic Concepts -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-8 section-title">消息队列的基本概念</h2>
                <p class="text-lg leading-relaxed text-gray-700 mb-8">
                    消息队列是一种基于生产者-消费者模式的通信方式，生产者将消息推送到队列，消费者从队列中获取并处理消息。
                </p>
                
                <!-- Architecture Diagram -->
                <div class="mb-8">
                    <div class="mermaid">
                        graph LR
                            A[生产者] -->|发送消息| B[消息队列]
                            B -->|拉取消息| C[消费者1]
                            B -->|拉取消息| D[消费者2]
                            B -->|拉取消息| E[消费者3]
                            
                            style A fill:#667eea,stroke:#fff,stroke-width:2px,color:#fff
                            style B fill:#764ba2,stroke:#fff,stroke-width:2px,color:#fff
                            style C fill:#4ade80,stroke:#fff,stroke-width:2px,color:#fff
                            style D fill:#4ade80,stroke:#fff,stroke-width:2px,color:#fff
                            style E fill:#4ade80,stroke:#fff,stroke-width:2px,color:#fff
                    </div>
                </div>
                
                <div class="grid md:grid-cols-3 gap-6 mt-8">
                    <div class="card-hover bg-gray-50 rounded-xl p-6">
                        <div class="feature-icon">
                            <i class="fas fa-paper-plane"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3">生产者（Producer）</h3>
                        <p class="text-gray-600">负责发送消息到队列，可以是任何需要发送数据的应用或服务。</p>
                    </div>
                    <div class="card-hover bg-gray-50 rounded-xl p-6">
                        <div class="feature-icon">
                            <i class="fas fa-database"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3">消息队列（Queue）</h3>
                        <p class="text-gray-600">存储并传输消息的中间件，负责消息的持久化和分发。</p>
                    </div>
                    <div class="card-hover bg-gray-50 rounded-xl p-6">
                        <div class="feature-icon">
                            <i class="fas fa-user-check"></i>
                        </div>
                        <h3 class="text-xl font-semibold mb-3">消费者（Consumer）</h3>
                        <p class="text-gray-600">从队列中读取并处理消息，可以有多个消费者并行处理。</p>
                    </div>
                </div>
            </div>
        </section>

        <!-- Core Application Scenarios -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 text-center">核心应用场景</h2>
            <div class="grid md:grid-cols-2 gap-8">
                <div class="mq-card card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-unlink mr-3 text-purple-600"></i>
                        系统解耦
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        在传统的同步调用模式下，服务之间的强依赖性使得系统的可扩展性较差。通过引入消息队列，服务之间可以通过异步消息传递进行通信，从而降低耦合度。
                    </p>
                </div>
                
                <div class="mq-card card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-chart-line mr-3 text-purple-600"></i>
                        流量削峰填谷
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        在高并发系统中，直接访问数据库可能导致数据库负载过高。消息队列可以起到缓冲作用，消费者按照一定速率处理消息，避免数据库压力过大。
                    </p>
                </div>
                
                <div class="mq-card card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-sync-alt mr-3 text-purple-600"></i>
                        异步处理
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        对于不需要立即返回结果的任务（如日志记录、邮件发送等），可以采用消息队列进行异步处理，提高系统响应速度。
                    </p>
                </div>
                
                <div class="mq-card card-hover">
                    <h3 class="text-2xl font-semibold mb-4 flex items-center">
                        <i class="fas fa-handshake mr-3 text-purple-600"></i>
                        分布式事务
                    </h3>
                    <p class="text-gray-700 leading-relaxed">
                        在分布式系统中，事务一致性是一个挑战。使用消息队列的事务消息机制可以保证操作的最终一致性。
                    </p>
                </div>
            </div>
        </section>

        <!-- Message Queue Implementations -->
        <section class="mb-16">
            <div class="bg-white rounded-2xl shadow-lg p-8">
                <h2 class="text-3xl font-bold mb-8 section-title">主流消息队列对比</h2>
                
                <div class="grid md:grid-cols-2 gap-6">
                    <div class="border-2 border-gray-100 rounded-xl p-6 hover:border-purple-400 transition-all">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 bg-orange-500 rounded-lg flex items-center justify-center text-white font-bold mr-4">R</div>
                            <h3 class="text-2xl font-semibold">RabbitMQ</h3>
                        </div>
                        <p class="text-gray-700 mb-4">基于 AMQP 协议，功能丰富，适用于复杂的消息传递场景。</p>
                        <div class="flex flex-wrap">
                            <span class="tech-badge">持久化消息</span>
                            <span class="tech-badge">事务支持</span>
                            <span class="tech-badge">金融业务</span>
                        </div>
                    </div>
                    
                    <div class="border-2 border-gray-100 rounded-xl p-6 hover:border-purple-400 transition-all">
                        <div class="flex items-center mb-4">
                            <div class="w-12 h-12 bg-blue-600 rounded-lg flex items-center justify-center text-white font-bold mr-4">K</div>
                            <h3 class="text-2xl font-semibold">Kafka</h3>
                        </div>
                        <p class="text-gray-700 mb-4">主要用于高吞吐量日志和流式数据处理。</p>
                        <div class="flex flex-wrap">
                            <span class="tech-badge">高吞吐量</span>
                            <span class="tech-badge">分区存储</span>
                            <span class="tech-badge">日志收集</span>
                        </div>
                